package controllers;


import models.ApplicationUser;
import play.mvc.Controller;

import java.util.List;


public class UserList extends Controller {
    public static void list() {
        List<ApplicationUser> members = ApplicationUser.findAll();
        String uid = session.get("uid");
        ApplicationUser currentMember = ApplicationUser.findById(Long.parseLong(uid));
        render(members, currentMember);
    }

    public static void changeNamePage(String oldName) {
        render(oldName);

    }

    public static void changeName(String oldName, String newName) {
        ApplicationUser member = ApplicationUser.find("byName", oldName).first();
        member.name = newName;
        member.save();

    }

    public static void changeBirthDate(String oldBirthDate, String newBirthDate) {
        ApplicationUser member = ApplicationUser.findById(Long.parseLong(session.get("uid")));
        member.dateOfBirthday = newBirthDate;
        member.save();

    }

    public static void changeBirthDatePage(String oldBirthDate) {
        render(oldBirthDate);

    }

    public static void changeEmail(String oldEmail, String newEmail) {
        ApplicationUser member = ApplicationUser.findById(Long.parseLong(session.get("uid")));
        member.email = newEmail;
        member.save();

    }

    public static void changeEmailPage(String oldEmail) {
        render(oldEmail);

    }

    public static void changeCountry(String oldCountry, String newCountry) {
        ApplicationUser member = ApplicationUser.findById(Long.parseLong(session.get("uid")));
        member.country = newCountry;
        member.save();

    }

    public static void changeCountryPage(String oldCountry) {
        render(oldCountry);

    }

    public static void changeLanguage(String oldLanguage, String newLanguage) {
        ApplicationUser member = ApplicationUser.findById(Long.parseLong(session.get("uid")));
        member.language = newLanguage;
        member.save();

    }

    public static void changeLanguagePage(String oldLanguage) {
        render(oldLanguage);

    }
}
